﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using InfoExpress.HIV.Domains;
using InfoExpress.HIV.DataAccess;

#endregion

namespace InfoExpress.HIV.DataAccess.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="BenhNhanDangKyProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class BenhNhanDangKyProviderBaseCore : EntityProviderBase<InfoExpress.HIV.Domains.BenhNhanDangKy, InfoExpress.HIV.Domains.BenhNhanDangKyKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, InfoExpress.HIV.Domains.BenhNhanDangKyKey key)
		{
			return Delete(transactionManager, key.BenhNhanId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_benhNhanId">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _benhNhanId)
		{
			return Delete(null, _benhNhanId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_benhNhanId">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _benhNhanId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_TrangThai_BenhNhanDangKy key.
		///		FK_TrangThai_BenhNhanDangKy Description: 
		/// </summary>
		/// <param name="_trangThaiId"></param>
		/// <returns>Returns a typed collection of InfoExpress.HIV.Domains.BenhNhanDangKy objects.</returns>
		public TList<BenhNhanDangKy> GetByTrangThaiId(System.Int32 _trangThaiId)
		{
			int count = -1;
			return GetByTrangThaiId(_trangThaiId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_TrangThai_BenhNhanDangKy key.
		///		FK_TrangThai_BenhNhanDangKy Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_trangThaiId"></param>
		/// <returns>Returns a typed collection of InfoExpress.HIV.Domains.BenhNhanDangKy objects.</returns>
		/// <remarks></remarks>
		public TList<BenhNhanDangKy> GetByTrangThaiId(TransactionManager transactionManager, System.Int32 _trangThaiId)
		{
			int count = -1;
			return GetByTrangThaiId(transactionManager, _trangThaiId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_TrangThai_BenhNhanDangKy key.
		///		FK_TrangThai_BenhNhanDangKy Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_trangThaiId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of InfoExpress.HIV.Domains.BenhNhanDangKy objects.</returns>
		public TList<BenhNhanDangKy> GetByTrangThaiId(TransactionManager transactionManager, System.Int32 _trangThaiId, int start, int pageLength)
		{
			int count = -1;
			return GetByTrangThaiId(transactionManager, _trangThaiId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_TrangThai_BenhNhanDangKy key.
		///		fKTrangThaiBenhNhanDangKy Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_trangThaiId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of InfoExpress.HIV.Domains.BenhNhanDangKy objects.</returns>
		public TList<BenhNhanDangKy> GetByTrangThaiId(System.Int32 _trangThaiId, int start, int pageLength)
		{
			int count =  -1;
			return GetByTrangThaiId(null, _trangThaiId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_TrangThai_BenhNhanDangKy key.
		///		fKTrangThaiBenhNhanDangKy Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_trangThaiId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of InfoExpress.HIV.Domains.BenhNhanDangKy objects.</returns>
		public TList<BenhNhanDangKy> GetByTrangThaiId(System.Int32 _trangThaiId, int start, int pageLength,out int count)
		{
			return GetByTrangThaiId(null, _trangThaiId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_TrangThai_BenhNhanDangKy key.
		///		FK_TrangThai_BenhNhanDangKy Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_trangThaiId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of InfoExpress.HIV.Domains.BenhNhanDangKy objects.</returns>
		public abstract TList<BenhNhanDangKy> GetByTrangThaiId(TransactionManager transactionManager, System.Int32 _trangThaiId, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override InfoExpress.HIV.Domains.BenhNhanDangKy Get(TransactionManager transactionManager, InfoExpress.HIV.Domains.BenhNhanDangKyKey key, int start, int pageLength)
		{
			return GetByBenhNhanId(transactionManager, key.BenhNhanId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_BenhNhanDangKy index.
		/// </summary>
		/// <param name="_benhNhanId"></param>
		/// <returns>Returns an instance of the <see cref="InfoExpress.HIV.Domains.BenhNhanDangKy"/> class.</returns>
		public InfoExpress.HIV.Domains.BenhNhanDangKy GetByBenhNhanId(System.Int32 _benhNhanId)
		{
			int count = -1;
			return GetByBenhNhanId(null,_benhNhanId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_BenhNhanDangKy index.
		/// </summary>
		/// <param name="_benhNhanId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="InfoExpress.HIV.Domains.BenhNhanDangKy"/> class.</returns>
		public InfoExpress.HIV.Domains.BenhNhanDangKy GetByBenhNhanId(System.Int32 _benhNhanId, int start, int pageLength)
		{
			int count = -1;
			return GetByBenhNhanId(null, _benhNhanId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_BenhNhanDangKy index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_benhNhanId"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="InfoExpress.HIV.Domains.BenhNhanDangKy"/> class.</returns>
		public InfoExpress.HIV.Domains.BenhNhanDangKy GetByBenhNhanId(TransactionManager transactionManager, System.Int32 _benhNhanId)
		{
			int count = -1;
			return GetByBenhNhanId(transactionManager, _benhNhanId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_BenhNhanDangKy index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_benhNhanId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="InfoExpress.HIV.Domains.BenhNhanDangKy"/> class.</returns>
		public InfoExpress.HIV.Domains.BenhNhanDangKy GetByBenhNhanId(TransactionManager transactionManager, System.Int32 _benhNhanId, int start, int pageLength)
		{
			int count = -1;
			return GetByBenhNhanId(transactionManager, _benhNhanId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_BenhNhanDangKy index.
		/// </summary>
		/// <param name="_benhNhanId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="InfoExpress.HIV.Domains.BenhNhanDangKy"/> class.</returns>
		public InfoExpress.HIV.Domains.BenhNhanDangKy GetByBenhNhanId(System.Int32 _benhNhanId, int start, int pageLength, out int count)
		{
			return GetByBenhNhanId(null, _benhNhanId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_BenhNhanDangKy index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_benhNhanId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="InfoExpress.HIV.Domains.BenhNhanDangKy"/> class.</returns>
		public abstract InfoExpress.HIV.Domains.BenhNhanDangKy GetByBenhNhanId(TransactionManager transactionManager, System.Int32 _benhNhanId, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#region _BenhNhanDangKy_DsBenhNhanChuaDuyet 
		
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_DsBenhNhanChuaDuyet' stored procedure. 
		/// </summary>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet DsBenhNhanChuaDuyet()
		{
			return DsBenhNhanChuaDuyet(null, 0, int.MaxValue );
		}
		
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_DsBenhNhanChuaDuyet' stored procedure. 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet DsBenhNhanChuaDuyet(int start, int pageLength)
		{
			return DsBenhNhanChuaDuyet(null, start, pageLength );
		}
				
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_DsBenhNhanChuaDuyet' stored procedure. 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet DsBenhNhanChuaDuyet(TransactionManager transactionManager)
		{
			return DsBenhNhanChuaDuyet(transactionManager, 0, int.MaxValue );
		}
		
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_DsBenhNhanChuaDuyet' stored procedure. 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet DsBenhNhanChuaDuyet(TransactionManager transactionManager, int start, int pageLength );
		
		#endregion
		
		#region _BenhNhanDangKy_DsBenhNhanTheoTrangThai 
		
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_DsBenhNhanTheoTrangThai' stored procedure. 
		/// </summary>
		/// <param name="maDonVi"> A <c>System.String</c> instance.</param>
		/// <param name="trangThaiId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="tuNgay"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="denNgay"> A <c>System.DateTime?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;BenhNhanDangKy&gt;"/> instance.</returns>
		public TList<BenhNhanDangKy> DsBenhNhanTheoTrangThai(System.String maDonVi, System.Int32? trangThaiId, System.DateTime? tuNgay, System.DateTime? denNgay)
		{
			return DsBenhNhanTheoTrangThai(null, 0, int.MaxValue , maDonVi, trangThaiId, tuNgay, denNgay);
		}
		
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_DsBenhNhanTheoTrangThai' stored procedure. 
		/// </summary>
		/// <param name="maDonVi"> A <c>System.String</c> instance.</param>
		/// <param name="trangThaiId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="tuNgay"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="denNgay"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;BenhNhanDangKy&gt;"/> instance.</returns>
		public TList<BenhNhanDangKy> DsBenhNhanTheoTrangThai(int start, int pageLength, System.String maDonVi, System.Int32? trangThaiId, System.DateTime? tuNgay, System.DateTime? denNgay)
		{
			return DsBenhNhanTheoTrangThai(null, start, pageLength , maDonVi, trangThaiId, tuNgay, denNgay);
		}
				
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_DsBenhNhanTheoTrangThai' stored procedure. 
		/// </summary>
		/// <param name="maDonVi"> A <c>System.String</c> instance.</param>
		/// <param name="trangThaiId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="tuNgay"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="denNgay"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;BenhNhanDangKy&gt;"/> instance.</returns>
		public TList<BenhNhanDangKy> DsBenhNhanTheoTrangThai(TransactionManager transactionManager, System.String maDonVi, System.Int32? trangThaiId, System.DateTime? tuNgay, System.DateTime? denNgay)
		{
			return DsBenhNhanTheoTrangThai(transactionManager, 0, int.MaxValue , maDonVi, trangThaiId, tuNgay, denNgay);
		}
		
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_DsBenhNhanTheoTrangThai' stored procedure. 
		/// </summary>
		/// <param name="maDonVi"> A <c>System.String</c> instance.</param>
		/// <param name="trangThaiId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="tuNgay"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="denNgay"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;BenhNhanDangKy&gt;"/> instance.</returns>
		public abstract TList<BenhNhanDangKy> DsBenhNhanTheoTrangThai(TransactionManager transactionManager, int start, int pageLength , System.String maDonVi, System.Int32? trangThaiId, System.DateTime? tuNgay, System.DateTime? denNgay);
		
		#endregion
		
		#region _BenhNhanDangKy_LayThongTinDayDu 
		
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_LayThongTinDayDu' stored procedure. 
		/// </summary>
		/// <param name="benhNhanId"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet LayThongTinDayDu(System.Int32? benhNhanId)
		{
			return LayThongTinDayDu(null, 0, int.MaxValue , benhNhanId);
		}
		
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_LayThongTinDayDu' stored procedure. 
		/// </summary>
		/// <param name="benhNhanId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet LayThongTinDayDu(int start, int pageLength, System.Int32? benhNhanId)
		{
			return LayThongTinDayDu(null, start, pageLength , benhNhanId);
		}
				
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_LayThongTinDayDu' stored procedure. 
		/// </summary>
		/// <param name="benhNhanId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet LayThongTinDayDu(TransactionManager transactionManager, System.Int32? benhNhanId)
		{
			return LayThongTinDayDu(transactionManager, 0, int.MaxValue , benhNhanId);
		}
		
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_LayThongTinDayDu' stored procedure. 
		/// </summary>
		/// <param name="benhNhanId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet LayThongTinDayDu(TransactionManager transactionManager, int start, int pageLength , System.Int32? benhNhanId);
		
		#endregion
		
		#region _BenhNhanDangKy_LaySttToiDa 
		
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_LaySttToiDa' stored procedure. 
		/// </summary>
		/// <param name="maDonVi"> A <c>System.String</c> instance.</param>
		/// <param name="maPhanLoai"> A <c>System.Int32?</c> instance.</param>
		/// <param name="year2Digit"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet LaySttToiDa(System.String maDonVi, System.Int32? maPhanLoai, System.String year2Digit)
		{
			return LaySttToiDa(null, 0, int.MaxValue , maDonVi, maPhanLoai, year2Digit);
		}
		
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_LaySttToiDa' stored procedure. 
		/// </summary>
		/// <param name="maDonVi"> A <c>System.String</c> instance.</param>
		/// <param name="maPhanLoai"> A <c>System.Int32?</c> instance.</param>
		/// <param name="year2Digit"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet LaySttToiDa(int start, int pageLength, System.String maDonVi, System.Int32? maPhanLoai, System.String year2Digit)
		{
			return LaySttToiDa(null, start, pageLength , maDonVi, maPhanLoai, year2Digit);
		}
				
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_LaySttToiDa' stored procedure. 
		/// </summary>
		/// <param name="maDonVi"> A <c>System.String</c> instance.</param>
		/// <param name="maPhanLoai"> A <c>System.Int32?</c> instance.</param>
		/// <param name="year2Digit"> A <c>System.String</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet LaySttToiDa(TransactionManager transactionManager, System.String maDonVi, System.Int32? maPhanLoai, System.String year2Digit)
		{
			return LaySttToiDa(transactionManager, 0, int.MaxValue , maDonVi, maPhanLoai, year2Digit);
		}
		
		/// <summary>
		///	This method wrap the '_BenhNhanDangKy_LaySttToiDa' stored procedure. 
		/// </summary>
		/// <param name="maDonVi"> A <c>System.String</c> instance.</param>
		/// <param name="maPhanLoai"> A <c>System.Int32?</c> instance.</param>
		/// <param name="year2Digit"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet LaySttToiDa(TransactionManager transactionManager, int start, int pageLength , System.String maDonVi, System.Int32? maPhanLoai, System.String year2Digit);
		
		#endregion
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;BenhNhanDangKy&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;BenhNhanDangKy&gt;"/></returns>
		public static TList<BenhNhanDangKy> Fill(IDataReader reader, TList<BenhNhanDangKy> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				InfoExpress.HIV.Domains.BenhNhanDangKy c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("BenhNhanDangKy")
					.Append("|").Append((System.Int32)reader[((int)BenhNhanDangKyColumn.BenhNhanId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<BenhNhanDangKy>(
					key.ToString(), // EntityTrackingKey
					"BenhNhanDangKy",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new InfoExpress.HIV.Domains.BenhNhanDangKy();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.BenhNhanId = (System.Int32)reader[((int)BenhNhanDangKyColumn.BenhNhanId - 1)];
					c.MaDonVi = (System.String)reader[((int)BenhNhanDangKyColumn.MaDonVi - 1)];
					c.MaBenhNhan = (System.String)reader[((int)BenhNhanDangKyColumn.MaBenhNhan - 1)];
					c.NgayDangKy = (System.DateTime)reader[((int)BenhNhanDangKyColumn.NgayDangKy - 1)];
					c.NgayTao = (System.DateTime)reader[((int)BenhNhanDangKyColumn.NgayTao - 1)];
					c.UserTao = (System.String)reader[((int)BenhNhanDangKyColumn.UserTao - 1)];
					c.NgaySua = (System.DateTime)reader[((int)BenhNhanDangKyColumn.NgaySua - 1)];
					c.UserSua = (System.String)reader[((int)BenhNhanDangKyColumn.UserSua - 1)];
					c.TenBenhNhan = (System.String)reader[((int)BenhNhanDangKyColumn.TenBenhNhan - 1)];
					c.NgaySinh = (reader.IsDBNull(((int)BenhNhanDangKyColumn.NgaySinh - 1)))?null:(System.DateTime?)reader[((int)BenhNhanDangKyColumn.NgaySinh - 1)];
					c.GioiTinh = (System.Int32)reader[((int)BenhNhanDangKyColumn.GioiTinh - 1)];
					c.Cmnd = (reader.IsDBNull(((int)BenhNhanDangKyColumn.Cmnd - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.Cmnd - 1)];
					c.NgayCapCmnd = (reader.IsDBNull(((int)BenhNhanDangKyColumn.NgayCapCmnd - 1)))?null:(System.DateTime?)reader[((int)BenhNhanDangKyColumn.NgayCapCmnd - 1)];
					c.NoiCapCmnd = (reader.IsDBNull(((int)BenhNhanDangKyColumn.NoiCapCmnd - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.NoiCapCmnd - 1)];
					c.ThTruDuong = (reader.IsDBNull(((int)BenhNhanDangKyColumn.ThTruDuong - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.ThTruDuong - 1)];
					c.ThTruPhuong = (reader.IsDBNull(((int)BenhNhanDangKyColumn.ThTruPhuong - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.ThTruPhuong - 1)];
					c.ThTruQuan = (reader.IsDBNull(((int)BenhNhanDangKyColumn.ThTruQuan - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.ThTruQuan - 1)];
					c.ThTruTp = (reader.IsDBNull(((int)BenhNhanDangKyColumn.ThTruTp - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.ThTruTp - 1)];
					c.TmTruDuong = (reader.IsDBNull(((int)BenhNhanDangKyColumn.TmTruDuong - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.TmTruDuong - 1)];
					c.TmTruPhuong = (reader.IsDBNull(((int)BenhNhanDangKyColumn.TmTruPhuong - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.TmTruPhuong - 1)];
					c.TmTruQuan = (reader.IsDBNull(((int)BenhNhanDangKyColumn.TmTruQuan - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.TmTruQuan - 1)];
					c.TmTruTp = (reader.IsDBNull(((int)BenhNhanDangKyColumn.TmTruTp - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.TmTruTp - 1)];
					c.DienThoai = (reader.IsDBNull(((int)BenhNhanDangKyColumn.DienThoai - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.DienThoai - 1)];
					c.Email = (reader.IsDBNull(((int)BenhNhanDangKyColumn.Email - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.Email - 1)];
					c.HinhAnh = (reader.IsDBNull(((int)BenhNhanDangKyColumn.HinhAnh - 1)))?null:(System.Byte[])reader[((int)BenhNhanDangKyColumn.HinhAnh - 1)];
					c.VanTay = (reader.IsDBNull(((int)BenhNhanDangKyColumn.VanTay - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.VanTay - 1)];
					c.GhiChu = (reader.IsDBNull(((int)BenhNhanDangKyColumn.GhiChu - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.GhiChu - 1)];
					c.NgayDuyet = (reader.IsDBNull(((int)BenhNhanDangKyColumn.NgayDuyet - 1)))?null:(System.DateTime?)reader[((int)BenhNhanDangKyColumn.NgayDuyet - 1)];
					c.UserDuyet = (reader.IsDBNull(((int)BenhNhanDangKyColumn.UserDuyet - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.UserDuyet - 1)];
					c.GhiChuDuyet = (reader.IsDBNull(((int)BenhNhanDangKyColumn.GhiChuDuyet - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.GhiChuDuyet - 1)];
					c.NgayDangKyHiv = (reader.IsDBNull(((int)BenhNhanDangKyColumn.NgayDangKyHiv - 1)))?null:(System.DateTime?)reader[((int)BenhNhanDangKyColumn.NgayDangKyHiv - 1)];
					c.MaNgheNghiep = (reader.IsDBNull(((int)BenhNhanDangKyColumn.MaNgheNghiep - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.MaNgheNghiep - 1)];
					c.DoiTuongId = (reader.IsDBNull(((int)BenhNhanDangKyColumn.DoiTuongId - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.DoiTuongId - 1)];
					c.NguyCoLayNhiemId = (reader.IsDBNull(((int)BenhNhanDangKyColumn.NguyCoLayNhiemId - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.NguyCoLayNhiemId - 1)];
					c.MaXetNghiem = (reader.IsDBNull(((int)BenhNhanDangKyColumn.MaXetNghiem - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.MaXetNghiem - 1)];
					c.MaDuyet = (reader.IsDBNull(((int)BenhNhanDangKyColumn.MaDuyet - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.MaDuyet - 1)];
					c.TrangThaiId = (System.Int32)reader[((int)BenhNhanDangKyColumn.TrangThaiId - 1)];
					c.DeleteFlag = (System.Boolean)reader[((int)BenhNhanDangKyColumn.DeleteFlag - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="InfoExpress.HIV.Domains.BenhNhanDangKy"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="InfoExpress.HIV.Domains.BenhNhanDangKy"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, InfoExpress.HIV.Domains.BenhNhanDangKy entity)
		{
			if (!reader.Read()) return;
			
			entity.BenhNhanId = (System.Int32)reader[((int)BenhNhanDangKyColumn.BenhNhanId - 1)];
			entity.MaDonVi = (System.String)reader[((int)BenhNhanDangKyColumn.MaDonVi - 1)];
			entity.MaBenhNhan = (System.String)reader[((int)BenhNhanDangKyColumn.MaBenhNhan - 1)];
			entity.NgayDangKy = (System.DateTime)reader[((int)BenhNhanDangKyColumn.NgayDangKy - 1)];
			entity.NgayTao = (System.DateTime)reader[((int)BenhNhanDangKyColumn.NgayTao - 1)];
			entity.UserTao = (System.String)reader[((int)BenhNhanDangKyColumn.UserTao - 1)];
			entity.NgaySua = (System.DateTime)reader[((int)BenhNhanDangKyColumn.NgaySua - 1)];
			entity.UserSua = (System.String)reader[((int)BenhNhanDangKyColumn.UserSua - 1)];
			entity.TenBenhNhan = (System.String)reader[((int)BenhNhanDangKyColumn.TenBenhNhan - 1)];
			entity.NgaySinh = (reader.IsDBNull(((int)BenhNhanDangKyColumn.NgaySinh - 1)))?null:(System.DateTime?)reader[((int)BenhNhanDangKyColumn.NgaySinh - 1)];
			entity.GioiTinh = (System.Int32)reader[((int)BenhNhanDangKyColumn.GioiTinh - 1)];
			entity.Cmnd = (reader.IsDBNull(((int)BenhNhanDangKyColumn.Cmnd - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.Cmnd - 1)];
			entity.NgayCapCmnd = (reader.IsDBNull(((int)BenhNhanDangKyColumn.NgayCapCmnd - 1)))?null:(System.DateTime?)reader[((int)BenhNhanDangKyColumn.NgayCapCmnd - 1)];
			entity.NoiCapCmnd = (reader.IsDBNull(((int)BenhNhanDangKyColumn.NoiCapCmnd - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.NoiCapCmnd - 1)];
			entity.ThTruDuong = (reader.IsDBNull(((int)BenhNhanDangKyColumn.ThTruDuong - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.ThTruDuong - 1)];
			entity.ThTruPhuong = (reader.IsDBNull(((int)BenhNhanDangKyColumn.ThTruPhuong - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.ThTruPhuong - 1)];
			entity.ThTruQuan = (reader.IsDBNull(((int)BenhNhanDangKyColumn.ThTruQuan - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.ThTruQuan - 1)];
			entity.ThTruTp = (reader.IsDBNull(((int)BenhNhanDangKyColumn.ThTruTp - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.ThTruTp - 1)];
			entity.TmTruDuong = (reader.IsDBNull(((int)BenhNhanDangKyColumn.TmTruDuong - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.TmTruDuong - 1)];
			entity.TmTruPhuong = (reader.IsDBNull(((int)BenhNhanDangKyColumn.TmTruPhuong - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.TmTruPhuong - 1)];
			entity.TmTruQuan = (reader.IsDBNull(((int)BenhNhanDangKyColumn.TmTruQuan - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.TmTruQuan - 1)];
			entity.TmTruTp = (reader.IsDBNull(((int)BenhNhanDangKyColumn.TmTruTp - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.TmTruTp - 1)];
			entity.DienThoai = (reader.IsDBNull(((int)BenhNhanDangKyColumn.DienThoai - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.DienThoai - 1)];
			entity.Email = (reader.IsDBNull(((int)BenhNhanDangKyColumn.Email - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.Email - 1)];
			entity.HinhAnh = (reader.IsDBNull(((int)BenhNhanDangKyColumn.HinhAnh - 1)))?null:(System.Byte[])reader[((int)BenhNhanDangKyColumn.HinhAnh - 1)];
			entity.VanTay = (reader.IsDBNull(((int)BenhNhanDangKyColumn.VanTay - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.VanTay - 1)];
			entity.GhiChu = (reader.IsDBNull(((int)BenhNhanDangKyColumn.GhiChu - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.GhiChu - 1)];
			entity.NgayDuyet = (reader.IsDBNull(((int)BenhNhanDangKyColumn.NgayDuyet - 1)))?null:(System.DateTime?)reader[((int)BenhNhanDangKyColumn.NgayDuyet - 1)];
			entity.UserDuyet = (reader.IsDBNull(((int)BenhNhanDangKyColumn.UserDuyet - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.UserDuyet - 1)];
			entity.GhiChuDuyet = (reader.IsDBNull(((int)BenhNhanDangKyColumn.GhiChuDuyet - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.GhiChuDuyet - 1)];
			entity.NgayDangKyHiv = (reader.IsDBNull(((int)BenhNhanDangKyColumn.NgayDangKyHiv - 1)))?null:(System.DateTime?)reader[((int)BenhNhanDangKyColumn.NgayDangKyHiv - 1)];
			entity.MaNgheNghiep = (reader.IsDBNull(((int)BenhNhanDangKyColumn.MaNgheNghiep - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.MaNgheNghiep - 1)];
			entity.DoiTuongId = (reader.IsDBNull(((int)BenhNhanDangKyColumn.DoiTuongId - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.DoiTuongId - 1)];
			entity.NguyCoLayNhiemId = (reader.IsDBNull(((int)BenhNhanDangKyColumn.NguyCoLayNhiemId - 1)))?null:(System.Int32?)reader[((int)BenhNhanDangKyColumn.NguyCoLayNhiemId - 1)];
			entity.MaXetNghiem = (reader.IsDBNull(((int)BenhNhanDangKyColumn.MaXetNghiem - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.MaXetNghiem - 1)];
			entity.MaDuyet = (reader.IsDBNull(((int)BenhNhanDangKyColumn.MaDuyet - 1)))?null:(System.String)reader[((int)BenhNhanDangKyColumn.MaDuyet - 1)];
			entity.TrangThaiId = (System.Int32)reader[((int)BenhNhanDangKyColumn.TrangThaiId - 1)];
			entity.DeleteFlag = (System.Boolean)reader[((int)BenhNhanDangKyColumn.DeleteFlag - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="InfoExpress.HIV.Domains.BenhNhanDangKy"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="InfoExpress.HIV.Domains.BenhNhanDangKy"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, InfoExpress.HIV.Domains.BenhNhanDangKy entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.BenhNhanId = (System.Int32)dataRow["BenhNhanId"];
			entity.MaDonVi = (System.String)dataRow["MaDonVi"];
			entity.MaBenhNhan = (System.String)dataRow["MaBenhNhan"];
			entity.NgayDangKy = (System.DateTime)dataRow["NgayDangKy"];
			entity.NgayTao = (System.DateTime)dataRow["NgayTao"];
			entity.UserTao = (System.String)dataRow["UserTao"];
			entity.NgaySua = (System.DateTime)dataRow["NgaySua"];
			entity.UserSua = (System.String)dataRow["UserSua"];
			entity.TenBenhNhan = (System.String)dataRow["TenBenhNhan"];
			entity.NgaySinh = Convert.IsDBNull(dataRow["NgaySinh"]) ? null : (System.DateTime?)dataRow["NgaySinh"];
			entity.GioiTinh = (System.Int32)dataRow["GioiTinh"];
			entity.Cmnd = Convert.IsDBNull(dataRow["Cmnd"]) ? null : (System.String)dataRow["Cmnd"];
			entity.NgayCapCmnd = Convert.IsDBNull(dataRow["NgayCapCmnd"]) ? null : (System.DateTime?)dataRow["NgayCapCmnd"];
			entity.NoiCapCmnd = Convert.IsDBNull(dataRow["NoiCapCmnd"]) ? null : (System.String)dataRow["NoiCapCmnd"];
			entity.ThTruDuong = Convert.IsDBNull(dataRow["ThTruDuong"]) ? null : (System.String)dataRow["ThTruDuong"];
			entity.ThTruPhuong = Convert.IsDBNull(dataRow["ThTruPhuong"]) ? null : (System.Int32?)dataRow["ThTruPhuong"];
			entity.ThTruQuan = Convert.IsDBNull(dataRow["ThTruQuan"]) ? null : (System.Int32?)dataRow["ThTruQuan"];
			entity.ThTruTp = Convert.IsDBNull(dataRow["ThTruTp"]) ? null : (System.Int32?)dataRow["ThTruTp"];
			entity.TmTruDuong = Convert.IsDBNull(dataRow["TmTruDuong"]) ? null : (System.String)dataRow["TmTruDuong"];
			entity.TmTruPhuong = Convert.IsDBNull(dataRow["TmTruPhuong"]) ? null : (System.Int32?)dataRow["TmTruPhuong"];
			entity.TmTruQuan = Convert.IsDBNull(dataRow["TmTruQuan"]) ? null : (System.Int32?)dataRow["TmTruQuan"];
			entity.TmTruTp = Convert.IsDBNull(dataRow["TmTruTp"]) ? null : (System.Int32?)dataRow["TmTruTp"];
			entity.DienThoai = Convert.IsDBNull(dataRow["DienThoai"]) ? null : (System.String)dataRow["DienThoai"];
			entity.Email = Convert.IsDBNull(dataRow["Email"]) ? null : (System.String)dataRow["Email"];
			entity.HinhAnh = Convert.IsDBNull(dataRow["HinhAnh"]) ? null : (System.Byte[])dataRow["HinhAnh"];
			entity.VanTay = Convert.IsDBNull(dataRow["VanTay"]) ? null : (System.String)dataRow["VanTay"];
			entity.GhiChu = Convert.IsDBNull(dataRow["GhiChu"]) ? null : (System.String)dataRow["GhiChu"];
			entity.NgayDuyet = Convert.IsDBNull(dataRow["NgayDuyet"]) ? null : (System.DateTime?)dataRow["NgayDuyet"];
			entity.UserDuyet = Convert.IsDBNull(dataRow["UserDuyet"]) ? null : (System.String)dataRow["UserDuyet"];
			entity.GhiChuDuyet = Convert.IsDBNull(dataRow["GhiChuDuyet"]) ? null : (System.String)dataRow["GhiChuDuyet"];
			entity.NgayDangKyHiv = Convert.IsDBNull(dataRow["NgayDangKyHiv"]) ? null : (System.DateTime?)dataRow["NgayDangKyHiv"];
			entity.MaNgheNghiep = Convert.IsDBNull(dataRow["MaNgheNghiep"]) ? null : (System.String)dataRow["MaNgheNghiep"];
			entity.DoiTuongId = Convert.IsDBNull(dataRow["DoiTuongId"]) ? null : (System.Int32?)dataRow["DoiTuongId"];
			entity.NguyCoLayNhiemId = Convert.IsDBNull(dataRow["NguyCoLayNhiemId"]) ? null : (System.Int32?)dataRow["NguyCoLayNhiemId"];
			entity.MaXetNghiem = Convert.IsDBNull(dataRow["MaXetNghiem"]) ? null : (System.String)dataRow["MaXetNghiem"];
			entity.MaDuyet = Convert.IsDBNull(dataRow["MaDuyet"]) ? null : (System.String)dataRow["MaDuyet"];
			entity.TrangThaiId = (System.Int32)dataRow["TrangThaiId"];
			entity.DeleteFlag = (System.Boolean)dataRow["DeleteFlag"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="InfoExpress.HIV.Domains.BenhNhanDangKy"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">InfoExpress.HIV.Domains.BenhNhanDangKy Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, InfoExpress.HIV.Domains.BenhNhanDangKy entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region TrangThaiIdSource	
			if (CanDeepLoad(entity, "TrangThai|TrangThaiIdSource", deepLoadType, innerList) 
				&& entity.TrangThaiIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.TrangThaiId;
				TrangThai tmpEntity = EntityManager.LocateEntity<TrangThai>(EntityLocator.ConstructKeyFromPkItems(typeof(TrangThai), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.TrangThaiIdSource = tmpEntity;
				else
					entity.TrangThaiIdSource = DataRepository.TrangThaiProvider.GetById(transactionManager, entity.TrangThaiId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'TrangThaiIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.TrangThaiIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.TrangThaiProvider.DeepLoad(transactionManager, entity.TrangThaiIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion TrangThaiIdSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			// Deep load child collections  - Call GetByBenhNhanId methods when available
			
			#region ThayDoiPhacDoCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<ThayDoiPhacDo>|ThayDoiPhacDoCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'ThayDoiPhacDoCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.ThayDoiPhacDoCollection = DataRepository.ThayDoiPhacDoProvider.GetByBenhNhanId(transactionManager, entity.BenhNhanId);

				if (deep && entity.ThayDoiPhacDoCollection.Count > 0)
				{
					deepHandles.Add("ThayDoiPhacDoCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<ThayDoiPhacDo>) DataRepository.ThayDoiPhacDoProvider.DeepLoad,
						new object[] { transactionManager, entity.ThayDoiPhacDoCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region LichSuDieuTriCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<LichSuDieuTri>|LichSuDieuTriCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'LichSuDieuTriCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.LichSuDieuTriCollection = DataRepository.LichSuDieuTriProvider.GetByBenhNhanId(transactionManager, entity.BenhNhanId);

				if (deep && entity.LichSuDieuTriCollection.Count > 0)
				{
					deepHandles.Add("LichSuDieuTriCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<LichSuDieuTri>) DataRepository.LichSuDieuTriProvider.DeepLoad,
						new object[] { transactionManager, entity.LichSuDieuTriCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region ThayDoiDieuTriCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<ThayDoiDieuTri>|ThayDoiDieuTriCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'ThayDoiDieuTriCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.ThayDoiDieuTriCollection = DataRepository.ThayDoiDieuTriProvider.GetByBenhNhanId(transactionManager, entity.BenhNhanId);

				if (deep && entity.ThayDoiDieuTriCollection.Count > 0)
				{
					deepHandles.Add("ThayDoiDieuTriCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<ThayDoiDieuTri>) DataRepository.ThayDoiDieuTriProvider.DeepLoad,
						new object[] { transactionManager, entity.ThayDoiDieuTriCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region DieuTriCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<DieuTri>|DieuTriCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'DieuTriCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.DieuTriCollection = DataRepository.DieuTriProvider.GetByBenhNhanId(transactionManager, entity.BenhNhanId);

				if (deep && entity.DieuTriCollection.Count > 0)
				{
					deepHandles.Add("DieuTriCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<DieuTri>) DataRepository.DieuTriProvider.DeepLoad,
						new object[] { transactionManager, entity.DieuTriCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region ChuyenOpcBuffer
			// RelationshipType.OneToOne
			if (CanDeepLoad(entity, "ChuyenOpcBuffer|ChuyenOpcBuffer", deepLoadType, innerList))
			{
				entity.ChuyenOpcBuffer = DataRepository.ChuyenOpcBufferProvider.GetByBenhNhanId(transactionManager, entity.BenhNhanId);
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'ChuyenOpcBuffer' loaded. key " + entity.EntityTrackingKey);
				#endif 

				if (deep && entity.ChuyenOpcBuffer != null)
				{
					deepHandles.Add("ChuyenOpcBuffer",
						new KeyValuePair<Delegate, object>((DeepLoadSingleHandle< ChuyenOpcBuffer >) DataRepository.ChuyenOpcBufferProvider.DeepLoad,
						new object[] { transactionManager, entity.ChuyenOpcBuffer, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion 
			
			
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the InfoExpress.HIV.Domains.BenhNhanDangKy object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">InfoExpress.HIV.Domains.BenhNhanDangKy instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">InfoExpress.HIV.Domains.BenhNhanDangKy Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, InfoExpress.HIV.Domains.BenhNhanDangKy entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region TrangThaiIdSource
			if (CanDeepSave(entity, "TrangThai|TrangThaiIdSource", deepSaveType, innerList) 
				&& entity.TrangThaiIdSource != null)
			{
				DataRepository.TrangThaiProvider.Save(transactionManager, entity.TrangThaiIdSource);
				entity.TrangThaiId = entity.TrangThaiIdSource.Id;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();

			#region ChuyenOpcBuffer
			if (CanDeepSave(entity.ChuyenOpcBuffer, "ChuyenOpcBuffer|ChuyenOpcBuffer", deepSaveType, innerList))
			{

				if (entity.ChuyenOpcBuffer != null)
				{
					// update each child parent id with the real parent id (mostly used on insert)

					entity.ChuyenOpcBuffer.BenhNhanId = entity.BenhNhanId;
					//DataRepository.ChuyenOpcBufferProvider.Save(transactionManager, entity.ChuyenOpcBuffer);
					deepHandles.Add("ChuyenOpcBuffer",
						new KeyValuePair<Delegate, object>((DeepSaveSingleHandle< ChuyenOpcBuffer >) DataRepository.ChuyenOpcBufferProvider.DeepSave,
						new object[] { transactionManager, entity.ChuyenOpcBuffer, deepSaveType, childTypes, innerList }
					));
				}
			} 
			#endregion 
	
			#region List<ThayDoiPhacDo>
				if (CanDeepSave(entity.ThayDoiPhacDoCollection, "List<ThayDoiPhacDo>|ThayDoiPhacDoCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(ThayDoiPhacDo child in entity.ThayDoiPhacDoCollection)
					{
						if(child.BenhNhanIdSource != null)
						{
							child.BenhNhanId = child.BenhNhanIdSource.BenhNhanId;
						}
						else
						{
							child.BenhNhanId = entity.BenhNhanId;
						}

					}

					if (entity.ThayDoiPhacDoCollection.Count > 0 || entity.ThayDoiPhacDoCollection.DeletedItems.Count > 0)
					{
						//DataRepository.ThayDoiPhacDoProvider.Save(transactionManager, entity.ThayDoiPhacDoCollection);
						
						deepHandles.Add("ThayDoiPhacDoCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< ThayDoiPhacDo >) DataRepository.ThayDoiPhacDoProvider.DeepSave,
							new object[] { transactionManager, entity.ThayDoiPhacDoCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<LichSuDieuTri>
				if (CanDeepSave(entity.LichSuDieuTriCollection, "List<LichSuDieuTri>|LichSuDieuTriCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(LichSuDieuTri child in entity.LichSuDieuTriCollection)
					{
						if(child.BenhNhanIdSource != null)
						{
							child.BenhNhanId = child.BenhNhanIdSource.BenhNhanId;
						}
						else
						{
							child.BenhNhanId = entity.BenhNhanId;
						}

					}

					if (entity.LichSuDieuTriCollection.Count > 0 || entity.LichSuDieuTriCollection.DeletedItems.Count > 0)
					{
						//DataRepository.LichSuDieuTriProvider.Save(transactionManager, entity.LichSuDieuTriCollection);
						
						deepHandles.Add("LichSuDieuTriCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< LichSuDieuTri >) DataRepository.LichSuDieuTriProvider.DeepSave,
							new object[] { transactionManager, entity.LichSuDieuTriCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<ThayDoiDieuTri>
				if (CanDeepSave(entity.ThayDoiDieuTriCollection, "List<ThayDoiDieuTri>|ThayDoiDieuTriCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(ThayDoiDieuTri child in entity.ThayDoiDieuTriCollection)
					{
						if(child.BenhNhanIdSource != null)
						{
							child.BenhNhanId = child.BenhNhanIdSource.BenhNhanId;
						}
						else
						{
							child.BenhNhanId = entity.BenhNhanId;
						}

					}

					if (entity.ThayDoiDieuTriCollection.Count > 0 || entity.ThayDoiDieuTriCollection.DeletedItems.Count > 0)
					{
						//DataRepository.ThayDoiDieuTriProvider.Save(transactionManager, entity.ThayDoiDieuTriCollection);
						
						deepHandles.Add("ThayDoiDieuTriCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< ThayDoiDieuTri >) DataRepository.ThayDoiDieuTriProvider.DeepSave,
							new object[] { transactionManager, entity.ThayDoiDieuTriCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<DieuTri>
				if (CanDeepSave(entity.DieuTriCollection, "List<DieuTri>|DieuTriCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(DieuTri child in entity.DieuTriCollection)
					{
						if(child.BenhNhanIdSource != null)
						{
							child.BenhNhanId = child.BenhNhanIdSource.BenhNhanId;
						}
						else
						{
							child.BenhNhanId = entity.BenhNhanId;
						}

					}

					if (entity.DieuTriCollection.Count > 0 || entity.DieuTriCollection.DeletedItems.Count > 0)
					{
						//DataRepository.DieuTriProvider.Save(transactionManager, entity.DieuTriCollection);
						
						deepHandles.Add("DieuTriCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< DieuTri >) DataRepository.DieuTriProvider.DeepSave,
							new object[] { transactionManager, entity.DieuTriCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region BenhNhanDangKyChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>InfoExpress.HIV.Domains.BenhNhanDangKy</c>
	///</summary>
	public enum BenhNhanDangKyChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>TrangThai</c> at TrangThaiIdSource
		///</summary>
		[ChildEntityType(typeof(TrangThai))]
		TrangThai,
	
		///<summary>
		/// Collection of <c>BenhNhanDangKy</c> as OneToMany for ThayDoiPhacDoCollection
		///</summary>
		[ChildEntityType(typeof(TList<ThayDoiPhacDo>))]
		ThayDoiPhacDoCollection,

		///<summary>
		/// Collection of <c>BenhNhanDangKy</c> as OneToMany for LichSuDieuTriCollection
		///</summary>
		[ChildEntityType(typeof(TList<LichSuDieuTri>))]
		LichSuDieuTriCollection,

		///<summary>
		/// Collection of <c>BenhNhanDangKy</c> as OneToMany for ThayDoiDieuTriCollection
		///</summary>
		[ChildEntityType(typeof(TList<ThayDoiDieuTri>))]
		ThayDoiDieuTriCollection,

		///<summary>
		/// Collection of <c>BenhNhanDangKy</c> as OneToMany for DieuTriCollection
		///</summary>
		[ChildEntityType(typeof(TList<DieuTri>))]
		DieuTriCollection,
		///<summary>
		/// Entity <c>ChuyenOpcBuffer</c> as OneToOne for ChuyenOpcBuffer
		///</summary>
		[ChildEntityType(typeof(ChuyenOpcBuffer))]
		ChuyenOpcBuffer,
	}
	
	#endregion BenhNhanDangKyChildEntityTypes
	
	#region BenhNhanDangKyFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;BenhNhanDangKyColumn&gt;"/> class
	/// that is used exclusively with a <see cref="BenhNhanDangKy"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class BenhNhanDangKyFilterBuilder : SqlFilterBuilder<BenhNhanDangKyColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the BenhNhanDangKyFilterBuilder class.
		/// </summary>
		public BenhNhanDangKyFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the BenhNhanDangKyFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public BenhNhanDangKyFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the BenhNhanDangKyFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public BenhNhanDangKyFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion BenhNhanDangKyFilterBuilder
	
	#region BenhNhanDangKyParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;BenhNhanDangKyColumn&gt;"/> class
	/// that is used exclusively with a <see cref="BenhNhanDangKy"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class BenhNhanDangKyParameterBuilder : ParameterizedSqlFilterBuilder<BenhNhanDangKyColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the BenhNhanDangKyParameterBuilder class.
		/// </summary>
		public BenhNhanDangKyParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the BenhNhanDangKyParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public BenhNhanDangKyParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the BenhNhanDangKyParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public BenhNhanDangKyParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion BenhNhanDangKyParameterBuilder
	
	#region BenhNhanDangKySortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;BenhNhanDangKyColumn&gt;"/> class
	/// that is used exclusively with a <see cref="BenhNhanDangKy"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class BenhNhanDangKySortBuilder : SqlSortBuilder<BenhNhanDangKyColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the BenhNhanDangKySqlSortBuilder class.
		/// </summary>
		public BenhNhanDangKySortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion BenhNhanDangKySortBuilder
	
} // end namespace
